import * as types from './wareHouseMutationTypes';
import arrayUtil from '../../../common/arrayUtil';
// import assignDeep from 'assign-deep';

/**
 * mutations
 * @type {{}}
 */
const mutations = {

  [types.SYS_FILE_UPLOAD_QUERY_TOKEN](state) {
  },
  [types.SYS_FILE_UPLOAD_SAVE_FILE_BEGIN](state) {
  },
  [types.SYS_FILE_UPLOAD_SAVE_FILE_SUC](state, {newdata}) {

    let wareHouse = state.wareHouse || [];
    wareHouse.push(newdata);
    state.wareHouse = wareHouse;
  },
  [types.SYS_FILE_UPLOAD_UPDATE_SUC](state, {formData}) {
    let file = state.wareHouse.find((item) => {
      return item.warehouseId === formData.warehouseId;
    });
    file.combinationCode = formData.combinationCode;
    file.combinationName = formData.combinationName;
    file.beginDate = formData.beginDate;
    file.endDate = formData.endDate;
    file.transferReason = formData.transferReason;
    file.transferContent = formData.transferContent;
  },

  [types.SYS_FILE_UPLOAD_DELETE_SUC](state, {warehouseId}) {
    console.log(state.wareHouse)
    console.log(warehouseId)
    arrayUtil.removeItem(state.wareHouse, 'warehouseId', warehouseId);
  },

  [types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN](state) {
    state.wareHouse = [];
  },

  [types.SYS_FILE_UPLOAD_QUERY_FILES_SUC](state, {wareHouse}) {
    state.wareHouse = wareHouse || [];
  },

  [types.SYS_QUERY_WARES_TOTAL_BEGIN](state) {
    state.totalCount = 0;
  },

  [types.SYS_QUERY_WARES_TOTAL_SUC](state, {totalCount}) {
    state.totalCount = totalCount;
  },

  [types.SYS_QUERY_WARES_CURRENT_BEGIN](state) {
    state.currentPage = 0;
  },

  [types.SYS_QUERY_WARES_CURRENT_SUC](state, {currentPage}) {
    state.currentPage = currentPage;
  },

  [types.SYS_QUERY_COMBINATIONLIST_BEGIN](state) {
    state.combinationsList = [];
  },

  [types.SYS_QUERY_COMBINATIONLIST_SUC](state, {list}) {
    state.combinationsList = list || [];
  },


  [types.SYS_FILE_UPLOAD_QUERY_FUNDS_BEGIN](state) {
    state.wareHousefund = [];
  },

  [types.SYS_FILE_UPLOAD_QUERY_FUNDS_SUC](state, {wareHousefund}) {
    state.wareHousefund = wareHousefund || [];
  },

  [types.SYS_FUND_UPLOAD_DELETE_SUC](state, {mappingId}) {
    console.log(state.wareHousefund)
    console.log(mappingId)
    arrayUtil.removeItem(state.wareHousefund, 'mappingId', mappingId);
  },

  [types.SYS_FUND_UPLOAD_SAVE_FILE_SUC](state, {newdata}) {

    let wareHousefund = state.wareHousefund || [];
    wareHousefund.push(newdata);
    state.wareHousefund = wareHousefund;
  },
  [types.SYS_FUND_UPLOAD_UPDATE_SUC](state, {formData}) {
    let file = state.wareHousefund.find((item) => {
      return item.fundCode === formData.fundCode;
    });
    file.fundName = formData.fundName;
    file.percentBefore = formData.percentBefore;
    file.beginDate = formData.beginDate;
    file.percentNow = formData.percentNow;
    file.warehouseId = formData.warehouseId;

  }
};

export default mutations;
